﻿<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>书籍列表</title>
    <link rel="stylesheet" type="text/css" th:href="@{/manager/easyui/themes/default/easyui.css}">
    <link rel="stylesheet" type="text/css" th:href="@{/manager/easyui/themes/icon.css}">
    <script type="text/javascript" th:src="@{/manager/easyui/jquery.min.js}"></script>
    <script type="text/javascript" th:src="@{/manager/easyui/jquery.easyui.min.js}"></script>
    <script type="text/javascript">
        //工具栏
        var toolbar = [{
            text: '修改',
            iconCls: 'icon-edit',
            handler: function () {
                var row = $('#booklist').datagrid('getSelected');
                $('#dd').dialog('open');
                $("#bookname1").textbox('setValue',row.bookname);
                $("#price").textbox('setValue',row.price);
                $("#groupprice").textbox('setValue',row.groupprice);
                $("#bookintroduce").textbox('setValue',row.bookintroduce);
                $("#authorintroduce").textbox('setValue',row.authorintroduce);
            }
        }, '-', {
            text: '启用',
            iconCls: 'icon-ok',
            handler: function () {
                var row = $('#booklist').datagrid('getSelected');
                $.ajax({
                    type:'post',
                    url:'/manager/book/modifyEnFlagById',
                    data:{
                        "id":row.id,
                    },
                    dataType:'json',
                    success:function (data) {
                        if(data.status){
                            alert(data.msg);
                            location.reload();
                        }
                    }
                });
            }
        }, '-', {
            text: '禁用',
            iconCls: 'icon-cancel',
            handler: function () {
                var row = $('#booklist').datagrid('getSelected');
                $.ajax({
                    type:'post',
                    url:'/manager/book/modifyDisFlagById',
                    data:{
                        "id":row.id,
                    },
                    dataType:'json',
                    success:function (data) {
                        if(data.status){
                            alert(data.msg);
                            location.reload();
                        }
                    }
                });
            }
        }];
        $(function(){
            //初始化搜索下拉框
            $('#supplier_type').combobox({
                url:"/manager/supplier/findAll",
                valueField:'id',
                multiple: false,
                textField:'name',
                editable:true
            });
            $('#press_type').combobox({
                url:"/manager/press/findAll",
                valueField:'id',
                multiple: false,
                textField:'name',
                editable:true
            });

            //查询所有书籍列表
            $('#booklist').datagrid({
                title:'书籍列表',
                iconCls:'icon-save',
                url:'/manager/book/findByFuzzy',
                columns:[
                    [
                        {field:'bookname',title:'名称',width:100,align:'center'},
                        {field:'author',title:'作者',width:200,align:'center'},
                        {field:'price',title:'单价',width:80,align:'center'},
                        {field:'iSBN',title:'ISBN',width:200,align:'center'},
                        {field:'pressName',title:'出版社',width:200,align:'center'},
                        {field:'supplierName',title:'供货商',width:500,align:'center'},
                        {field:'flag',title:'状态',width:100,align:'center',formatter:function (value) {
                                var str = "";
                                if(0==value){
                                    str = "禁用";
                                }
                                if(1==value){
                                    str = "启用";
                                }
                                return str;
                            }}
                    ]
                ],
                toolbar: toolbar,
                pagination: true,//表示在datagrid设置分页
                pageSize: 5,
                singleSelect:true,
                pageList: [5,10,20]
            });

            //模糊查询书籍列表
            $("#submit_search").linkbutton({ iconCls: 'icon-search', plain: true })
                .click(function () {
                    $('#booklist').datagrid("load",{
                        "bookname":$('#bookname').val(),
                        "ISBN":$('#ISBN').val(),
                        "pressid":$('#press_type').val(),
                        "supplierid":$('#supplier_type').val()
                    });   //点击搜索
                });

            //初始化修改窗口
            $('#dd').dialog({
                title: 'My Dialog',
                width: 700,
                height: 500,
                closed: true,
                cache: false,
                href: '',
                modal: true,
                iconCls: 'icon-save',
                buttons: [{
                    text:'提交',
                    iconCls:'icon-ok',
                    handler:function(){
                        var row = $('#booklist').datagrid('getSelected');
                        let form = $('#ff')[0];
                        let formData = new FormData(form);
                        formData.append("file",$("#file")[0].files[0]);
                        formData.append("id",row.id);
                        $.ajax({
                            cache: false,
                            processData: false,
                            contentType: false,
                            type:'post',
                            url:'/manager/book/modifyById',
                            data:formData,
                            dataType:'json',
                            success:function (data) {
                                if(data.status){
                                    alert(data.msg);
                                    location.reload();
                                }else {
                                    alert(data.msg);
                                    location.reload();
                                }
                            }
                        });
                    }
                },{
                    text:'关闭',
                    handler:function(){
                        alert('cancel');;
                    }
                }]
            });

        });
    </script>
</head>
<body>
<form name="searchform" method="post" action="" id ="searchform">
    <td width="70" height="30"><strong>书籍查询：</strong></td>
    <td height="30">
        <input type="text" id="bookname" size=20 placeholder="书籍名称"/>
        <input type="text" id="ISBN" size=20 placeholder="ISBN"/>
        <input type="text" name="press_type" id="press_type"/>
        <input type="text" name="supplier_type" id="supplier_type"/>
        编辑推荐:<input type="checkbox" name="" value=""/>
        本周精选:<input type="checkbox" name="" value=""/>
    </td>
    <td>
        <a id="submit_search">搜索</a>
    </td>
</form>
<table id="booklist"></table>
<div id="dd">
    <div align="center" style="margin-top: 30px">
        <form id="ff">
            <div style="margin-bottom:20px">
                <input class="easyui-textbox" id="bookname1" name="bookname" style="width:50%" data-options="label:'书籍名称:',required:true">
            </div>
            <div style="margin-bottom:20px">
                <input class="easyui-textbox" id="price" name="price" style="width:50%" data-options="label:'单价:',required:true,validType:'email'">
            </div>
            <div style="margin-bottom:20px">
                <input class="easyui-textbox" id="groupprice" name="groupprice" style="width:50%" data-options="label:'团购价:',required:true">
            </div>
            <div style="margin-bottom:20px">
                <input class="easyui-textbox" id="bookintroduce" name="bookintroduce" style="width:50%;height:60px" data-options="label:'书籍简介:',multiline:true">
            </div>
            <div style="margin-bottom:20px">
                <input class="easyui-textbox" id="authorintroduce" name="authorintroduce" style="width:50%;height:60px" data-options="label:'作者简介:',multiline:true">
            </div>
            <div style="margin-bottom:20px">
                封面图片:&nbsp;&nbsp;&nbsp;&nbsp; <input id="file" name="file" type="file"/>
            </div>
            <div style="margin-bottom:20px">
                编辑推荐:<input type="checkbox" name="" value=""/>
                本周精选:<input type="checkbox" name="" value=""/>
            </div>
        </form>
    </div>
</div>
</body>
</html>